﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Business.Models;
using Business.Services;
using Store.ViewModels;
using StructureMap;

namespace Store.Controllers
{
    public class StoreController : Controller
    {
        private IStoreService storeService; 
        //
        // GET: /Store/

        public StoreController()
        {
            storeService = ObjectFactory.GetInstance<IStoreService>();
        }


        public ActionResult Index()
        {
            // Create a list of genres
            var genres = storeService.ListGenres();
            // Create our view model
            var viewModel = new StoreIndexViewModel
            {
                NumberOfGenres = genres.Count(),
                Genres = genres
            };
            return View(viewModel);
        }

        // GET: /Store/Browse/
        public ActionResult Browse(string genre)
        {
            var genreResult = storeService.GetGenre(genre);

            var viewModel = new StoreBrowseViewModel
                                {
                                    Genre = genreResult,
                                    Albums = genreResult.Albums
            };
            return View(viewModel);
        }

        //
        // GET: /Store/Details/5
        public ActionResult Details(int id)
        {
            var album = storeService.GetAlbum(id);
            return View(album);
        }

    }
}
